/**
 * Created by Administrator on 2017/12/28.
 */
/**
 * Created by Administrator on 2017/12/25.
 */
/*function bbb(){

 var dept={};
 var url=aa+"/standard/queryDepartment"
 $.ajax({
 url : url,
 type : "GET",
 async:false,
 dataType : "json",
 success : function(data) {
 console.log(data)
 },
 error : function() {
 alert("错误");
 }
 });

 var children=[];
 $.each(dept, function (b, v) {
 for (var i=1;i<=13;i++){
 if(v.type==i){
 var label={
 label:v.deptName,
 }
 }/!*if end*!/
 children[b]= label;
 }/!*for end*!/
 });/!*eacg end*!/
 //console.log(children)
 }

 function aaa(){

 var deptType={};
 var url=aa+"/standard/queryDepartmentType"
 $.ajax({
 url : url,
 type : "GET",
 async:false,
 dataType : "json",
 success : function(data) {
 deptType=data;
 },
 error : function() {
 alert("错误");
 }
 });
 var children=[];
 $.each(deptType, function (i, v) {
 console.log(v)

 v.dtid   =  []
 var label={
 label:v.name,
 }
 children[i]= label;
 });
 console.log(children)
 const tree = new G6.Tree({
 id: 'mountNode',
 height: window.innerHeight,
 fitView: 'autoSize',
 behaviourFilter: ['wheelZoom', 'dragBlank', 'dragCanvas']
 });
 tree.source({
 label: 'G6',
 children: children
 });
 tree.edge().shape('smooth');
 tree.render();

 }*/
ajax(aa + "/standard/queryComment", {}, function (res) {console.log(res)})
function begin() {
    ajax(aa + "/standard/queryDepartmentType", {}, function (res) {
        ajax(aa + "/standard/queryDepartment", {}, function (resp) {
            var data = {
                name: "部门类型",
                children: []
            };
            $.each(res, function (i, v) {
                var _data = {
                    name: v.name,
                    children: []
                };
                $.each(resp, function (index, value) {
                    if (value.type == v.dtid) {
                        _data.children.push({
                            name: value.deptName,
                            children: []
                        })
                    }
                })
                data.children.push(_data)
            })
            console.log(data);
            const tree = new G6.Tree({
                id: 'mountNode',            // 容器ID
                height: window.innerHeight,
                layoutCfg: {
                    // direction: 'LR', // 方向（LR/RL/H/TB/BT/V）
                    getHGap: function (/* d */) { // 横向间距
                        return 50;
                    },
                    getVGap: function (/* d */) { // 竖向间距
                        return 10;
                    },
                },
            });
            tree.source(data);
            tree.node()
                .label(function (obj) {
                    return obj.name;
                })
                .style({
                    fillOpacity: 1
                });
            tree.edge().shape('smooth');
            tree.render();
        }, function () {

        }, false)

    }, false)
}


function ajax(url, data, callback, fallcallback, asycn) {
    $.ajax({
        url: url,
        type: "POST",
        async: asycn,
        dataType: "json",
        data: data,
        success: function (data) {
            callback(data)
        },
        error: function () {
            fallcallback()
        }
    })
}

$(function(){
    begin()
})